package com.ly.common.utils.erp;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;

/**
 * 生成批号工具类
 */
public class BatchNumberGenerator {

    /**
     * 取当前时间戳
     * @return
     */
    public static String generateTimestamp() {
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
        return now.format(formatter);
    }

    /**
     * 随机数
     * @return
     */
    public static int generateRandom() {
        Random random = new Random();
        return random.nextInt(999999);
    }

    /**
     * 生成批号
     * @return
     */
    public static String generateBatchNumber() {
        String timestamp = generateTimestamp();
        int random = generateRandom();
        return timestamp + String.format("%06d", random);
    }

}
